package org.karelun.gef.commands;

import org.karelun.gef.helper.ConstantMessages;
import org.karelun.gef.model.AbstractConnectionModel;
import org.karelun.gef.model.Node;

public class DeleteConnectionCommand extends AbstractCommand {

    Node source;

    Node target;

    AbstractConnectionModel connection;

  
    public void setConnection(AbstractConnectionModel connection) {
        this.connection = connection;
    }

    public void setSource(Node source) {
        this.source = source;
    }

    public void setTarget(Node target) {
        this.target = target;
    }

    public void execute() {
    	source.removeSourceConnection(connection);
    	target.removeTargetConnection(connection);

    	connection.removeToDiagram();
        connection.setSource(null);
        connection.setTarget(null);
        
    }

    public String getLabel() {
        return ConstantMessages.DeleteConnCommand_Label_Text;
    }

    public void redo() {
        execute();
    }

    public void undo() {
        connection.setSource(source);
        connection.setTarget(target);
        source.addsourceConnection(connection);
        target.addtargetConnection(connection);
        
        connection.removeToDiagram();
    }
}